﻿using Library.AppWeb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MPR.Poker.DALEntity.SYS;
using MPR.Poker.Model;

namespace MPR.Poker.DALEntity.DataCache
{
    public class GetCombo
    {
        private static string m_ChangeTitle = "--Chọn--";

        public static string ChangeTitle
        {
            get { return m_ChangeTitle; }
            set { m_ChangeTitle = value; }
        }

        /// <summary>
        /// Lấy danh sách Quốc gia từ Cache
        /// </summary>
        /// <param name="lstCountry"></param>
        /// <returns></returns>
        public static ResultMessage Country(ref List<Model.LIS.LIS_Country> lstCountry)
        {
            ResultMessage objResultMessage = new ResultMessage();
            try
            {

                objResultMessage = GetDataCache.GetCountry(ref lstCountry);

                if (lstCountry == null) lstCountry = new List<Model.LIS.LIS_Country>();

                Model.LIS.LIS_Country objCountry = new Model.LIS.LIS_Country();
                objCountry.IDSys = 0;
                objCountry.CountryID = "0";
                objCountry.CountryName = ChangeTitle;

                lstCountry.Insert(0, objCountry);
            }
            catch (Exception objEx)
            {
                objResultMessage = new ResultMessage(true, ResultMessage.ErrorTypes.GetData, "Lấy danh sách quốc gia vào Combo", objEx);
                DAL_Error.Insert(objResultMessage, 0, "GetCombo --> Country");
                return objResultMessage;
            }
            return objResultMessage;
        }

        /// <summary>
        /// Lấy danh sách Tỉnh thành từ Cache
        /// </summary>
        /// <param name="lstProvince"></param>
        /// <returns></returns>
        public static ResultMessage Province(ref List<Model.LIS.LIS_Province> lstProvince)
        {
            ResultMessage objResultMessage = new ResultMessage();
            try
            {
                if (CacheProvider.IsSet(CacheProvider.SetCacheKeyCombo(CacheProvider.CacheKey_Province)))
                {
                    lstProvince = (List<Model.LIS.LIS_Province>)CacheProvider.Get(CacheProvider.SetCacheKeyCombo(CacheProvider.CacheKey_Province));
                }
                else
                {
                    objResultMessage = new DALEntity.LIS.DAL_Province().SelectToCache(ref lstProvince);

                    if (!objResultMessage.IsError)
                    {
                        CacheProvider.Set(CacheProvider.SetCacheKeyCombo(CacheProvider.CacheKey_Province), lstProvince);
                    }
                    else
                    {
                        return objResultMessage;
                    }
                }

                if (lstProvince == null) lstProvince = new List<Model.LIS.LIS_Province>();
                lstProvince = lstProvince.ToList();

                Model.LIS.LIS_Province objProvince = new Model.LIS.LIS_Province();
                objProvince.IDSys = 0;
                objProvince.ProvinceID = "0";
                objProvince.ProvinceName = ChangeTitle;

                lstProvince.Insert(0, objProvince);
            }
            catch (Exception objEx)
            {
                objResultMessage = new ResultMessage(true, ResultMessage.ErrorTypes.GetData, "Lấy danh sách tỉnh/thành vào Combo", objEx);
                DAL_Error.Insert(objResultMessage, 0, "GetCombo --> Province");
                return objResultMessage;
            }
            return new ResultMessage(false, ResultMessage.ErrorTypes.No_Error, "Lấy Cache danh sách Tỉnh/Thành thành công", string.Empty);
        }

        /// <summary>
        /// Lấy danh sách loại thành viên
        /// </summary>
        /// <param name="lstMemberType"></param>
        /// <returns></returns>
        public static ResultMessage MemberType(ref List<Model.SYS.SYS_MemberType> lstMemberType)
        {
            ResultMessage objResultMessage = new ResultMessage();
            try
            {

                objResultMessage = GetDataCache.GetMemberType(ref lstMemberType);

                if (lstMemberType == null) lstMemberType = new List<Model.SYS.SYS_MemberType>();

                Model.SYS.SYS_MemberType objMemberType = new Model.SYS.SYS_MemberType();
                objMemberType.IDSys = 0;
                objMemberType.MemberTypeName = ChangeTitle;

                lstMemberType.Insert(0, objMemberType);
            }
            catch (Exception objEx)
            {
                objResultMessage = new ResultMessage(true, ResultMessage.ErrorTypes.GetData, "Lấy danh sách loại thành viên vào Combo", objEx);
                DAL_Error.Insert(objResultMessage, 0, "GetCombo --> MemberType");
                return objResultMessage;
            }
            return objResultMessage;
        }

        /// <summary>
        /// Lấy danh sách đơn vị tiền tệ vào combo
        /// </summary>
        /// <param name="lstCurrency"></param>
        /// <returns></returns>
        public static ResultMessage Currency(ref List<Model.LIS.LIS_Currency> lstCurrency)
        {
            ResultMessage objResultMessage = new ResultMessage();
            try
            {

                objResultMessage = GetDataCache.GetCurrency(ref lstCurrency);

                if (lstCurrency == null) lstCurrency = new List<Model.LIS.LIS_Currency>();

                Model.LIS.LIS_Currency objCurrency = new Model.LIS.LIS_Currency();
                objCurrency.IDSys = 0;
                objCurrency.CurrencyID = "0";
                objCurrency.CurrencyName = ChangeTitle;

                lstCurrency.Insert(0, objCurrency);
            }
            catch (Exception objEx)
            {
                objResultMessage = new ResultMessage(true, ResultMessage.ErrorTypes.GetData, "Lấy danh sách đơn vị tiền tệ vào Combo", objEx);
                DAL_Error.Insert(objResultMessage, 0, "GetCombo --> Currency");
                return objResultMessage;
            }
            return objResultMessage;
        }

    }
}
